﻿<%@ Page Title="" Language="C#" MasterPageFile="~/FreeBooks.master" AutoEventWireup="true" CodeFile="AddBook.aspx.cs" Inherits="AddBook" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
<style>
span.required
{
    color:Red;
    font-size:10px;
}

span.date
{
    color:Red;
    font-size:10px;
}

span.number
{
    color:Red;
    font-size:10px;
}

span.emailid
{
    color:Red;
    font-size:10px;
}

table td
{
    padding:2px;
    vertical-align:top;
}

table td input[type=text],table td textarea,table td select
{
    width:98%;
}
</style>
<script src="Scripts/ValidationPlugin.js" type="text/javascript"></script>
<script language="javascript" type="text/ecmascript">

    $(document).ready(function () {
        $('.required').parent().prev().prev().append('<span class="required">&nbsp;&nbsp;*</span>');


        $('#<%=btnSave.ClientID %>').click(function () {
            var isValid = true;

            $('input.required').each(function () {
                if (this.value == '') {
                    isValid = false;
                    //$(this).parent().prev().prev().append('<span class="required">&nbsp;&nbsp;*</span>');
                }
            });

            $('textarea.required').each(function () {
                if (this.value == '') {
                    isValid = false;
                }
            });

            $('select.required').each(function () {
                if (this.value == '0') {
                    isValid = false;
                }
            });

            $('input.number').each(function () {
                if (!$(this).isNumber()) {
                    alert('not a valid no.');
                    isValid = false;
                }
            });

            $('input.date').each(function () {
                if (!$(this).isNumber()) {
                    alert('not a valid date.');
                    isValid = false;
                }
            });

            $('input.emailid').each(function () {
                if (!$(this).isNumber()) {
                    alert('not a valid email id.');
                    isValid = false;
                }
            });

            if (!isValid) {
                alert('* Please fill required fields.');
            }

            return false;// isValid;
        });
    });
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<div id="body">
<h4>Add Books to Store</h4>
<hr />
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr><td>Title</td><td>:</td><td><asp:TextBox ID="txtTitle" CssClass="required" runat="server"></asp:TextBox></td></tr>
<tr><td>Sub-Title</td><td>:</td><td><asp:TextBox ID="txtSubTitle" runat="server"></asp:TextBox></td></tr>
<tr><td>Summary</td><td>:</td><td><asp:TextBox ID="txtSummary" CssClass="required" Rows="5" TextMode="MultiLine" runat="server"></asp:TextBox></td></tr>
<tr><td>Edition</td><td>:</td><td><asp:TextBox ID="txtEdition" runat="server"></asp:TextBox></td></tr>
<tr><td>Author(s)</td><td>:</td><td><asp:TextBox ID="txtAuthors" CssClass="required" runat="server"></asp:TextBox></td></tr>
<tr><td>Publisher</td><td>:</td><td>
    <asp:DropDownList ID="ddlPublisher" CssClass="required" DataTextField="PublisherName" DataValueField="Id" runat="server">
    </asp:DropDownList>
<%--<asp:TextBox ID="txtPublisher" runat="server"></asp:TextBox>--%>
</td></tr>
<tr><td>Published Year</td><td>:</td><td><asp:TextBox ID="txtPublishedYear" CssClass="number" runat="server"></asp:TextBox></td></tr>
<tr><td>Category</td><td>:</td><td>
    <asp:DropDownList ID="ddlCategory" CssClass="required" DataTextField="CategoryName" DataValueField="Id" runat="server">
    </asp:DropDownList>
</td></tr>
<tr><td>Link</td><td>:</td><td><asp:TextBox ID="txtLink" CssClass="required" runat="server"></asp:TextBox></td></tr>
<tr><td>Thumbnail</td><td>:</td><td>
    <asp:FileUpload ID="fuThumbnail" runat="server" /></td></tr>
<tr><td colspan="3">&nbsp;</td></tr>
<tr><td>
    <asp:Button ID="btnSave" runat="server" Text="Save" onclick="btnSave_Click" /></td><td></td><td></td></tr>
</table>
</div>
</asp:Content>

